package com.witdata.mysql.mapper;

import com.mybatisflex.core.BaseMapper;
import com.witdata.mysql.domain.entity.TUser;
import com.witdata.mysql.domain.entity.UserLearningSession;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
/**
 *  映射层。
 *
 * @author 20331
 * @since 2025-04-10
 */
public interface UserLearningSessionMapper extends BaseMapper<UserLearningSession> {

    @Insert("insert into user_learning_session (user_id,username,starttime,lastactivitytime,status ) values (#{id},#{username},#{startTime},#{lastTime},'ACTIVE')")
    void saveUserName(@Param("id") long id,@Param("username") String username, @Param("startTime") long startTime,@Param("lastTime") long lastTime);

    @Update("update user_learning_session set lastactivitytime = #{lastActivityTime} , status = #{status},totaltime = #{totalTime} where username = #{username}")
    void save(UserLearningSession userActivity);
    @Select("select * from user_learning_session where username = #{userName}")
    UserLearningSession findByUserName(@Param("userName") String userName);

    @Select("select * from user_learning_session")
    List<UserLearningSession> findAll();

    @Update("update user_learning_session set lastactivitytime = #{lastTime} ,starttime = #{startTime},status = 'ACTIVE' where username = #{username}")
    void saveTimeByUserName(@Param("username") String username,@Param("startTime") long startTime, @Param("lastTime") long lastTime);

    @Select("select * from user_learning_session where username = #{userName}")
    List<UserLearningSession> getAllUserActivities(String userName);

    @Update("update user_learning_session set status = 'INACTIVE' where username = #{username}")
    void updateStatus(String username);

    @Select("select username,totaltime,starttime,lastactivitytime,status from user_learning_session")
    List<UserLearningSession> selectAllInfo();

    @Select("select * from t_user where username = #{username}")
    TUser findUserIdByUserName(String username);

    @Select("select * from t_user where username = #{username}")
    TUser selectByUserName(String username);
}
